package com.tyk.bookstore.front.system.service.impl;


import com.tyk.bookstore.front.common.cache.anno.ICache;
import com.tyk.bookstore.front.common.cache.constant.CacheConstant;
import com.tyk.bookstore.front.system.model.dto.CarouselDto;
import com.tyk.bookstore.front.system.model.vo.CarouselVo;
import com.tyk.bookstore.front.system.repository.CarouselRepository;
import com.tyk.bookstore.front.system.service.CarouselService;
import com.tyk.bookstore.front.system.util.MapStructPlatform;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;

/**
 * @author tyk
 * @description 轮播图管理
 */
@Service
@RequiredArgsConstructor
public class CarouselServiceImp implements CarouselService {

    private final CarouselRepository carouselRepository;

    private final MapStructPlatform mapStructPlatform;

    @Override
    @ICache(
            prefix = CacheConstant.PLATFORM_CAROUSE_PREFIX,
            expireTime = CacheConstant.PLATFORM_CAROUSE_EXPIRE_TIME,
            lockPrefix = CacheConstant.PLATFORM_CAROUSE_LOCK_PREFIX
    )
    public List<CarouselVo> getList() {
        List<CarouselDto> dtoList = carouselRepository.selectEnableList();
        dtoList.sort(Comparator.comparing(CarouselDto::getPriority));
        return mapStructPlatform.toCarouselVoList(dtoList);
    }
}
